package com.four.reimbursemanage.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.four.reimbursemanage.entity.Dailyapply;
import com.four.reimbursemanage.entity.Payapply;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

/**
 * 支付申请Mapper接口
 * 
 * @author lwy
 * @date 2024-09-13
 */
@Mapper
public interface PayapplyMapper extends BaseMapper<Payapply>
{
    /**
     * 查询支付申请
     * 
     * @param id 支付申请主键
     * @return 支付申请
     */
    @Select("select * from payapply where id=#{id}")
    public Payapply selectPayapplyById(Integer id);

    /**
     * 查询支付申请列表
     *
     * @return 支付申请集合
     */
    @Select("<script>" +
            "SELECT * FROM payapply" +
            "<where>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"transactor != null\">" +
            " <bind name=\"Key\" value=\"'%'+transactor+'%'\"/>" +
            "        transactor like #{Key} " +
            "    </if>" +
            "    <if test=\"payee != null\">" +
            "      and payee = #{payee}" +
            "   </if>" +
            "    <if test=\"paymoney != null\">" +
            "      and paymoney = #{paymoney}" +
            "   </if>" +
            "    <if test=\"type != type\">" +
            "      and type = #{type}" +
            "   </if>" +
            "    <if test=\"month != null\">" +
            "      and month = #{month}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Payapply> selectPayapplyList(int start, int size,
                                             String department, String transactor,
                                             String payee, String paymoney,
                                             String type, Date month, Integer state);

    /**
     * 查询本人支付申请列表
     *
     * @return 支付申请集合
     */
    @Select("<script>" +
            "SELECT * FROM payapply" +
            "<where>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"transactor != null\">" +
            " <bind name=\"Key\" value=\"'%'+transactor+'%'\"/>" +
            "        transactor like #{Key} " +
            "    </if>" +
            "    <if test=\"payee != null\">" +
            "      and payee = #{payee}" +
            "   </if>" +
            "    <if test=\"paymoney != null\">" +
            "      and paymoney = #{paymoney}" +
            "   </if>" +
            "    <if test=\"type != type\">" +
            "      and type = #{type}" +
            "   </if>" +
            "    <if test=\"month != null\">" +
            "      and month = #{month}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Payapply> selectByUser(int start, int size,
                                             String department, String transactor,
                                             String payee, String paymoney,
                                             String type, Date month, Integer state,  String number);

    /*分页*/
    @Select("<script>" +
            "SELECT count(*) FROM payapply" +
            "<where>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"transactor != null\">" +
            " <bind name=\"Key\" value=\"'%'+transactor+'%'\"/>" +
            "        transactor like #{Key} " +
            "    </if>" +
            "    <if test=\"payee != null\">" +
            "      and payee = #{payee}" +
            "   </if>" +
            "    <if test=\"paymoney != null\">" +
            "      and paymoney = #{paymoney}" +
            "   </if>" +
            "    <if test=\"type != null\">" +
            "      and type = #{type}" +
            "   </if>" +
            "    <if test=\"month != null\">" +
            "      and month = #{month}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countPayapply( String department, String transactor,
                              String payee, String paymoney,
                              String type, Date month, Integer state);


    /*本人--分页*/
    @Select("<script>" +
            "SELECT count(*) FROM payapply" +
            "<where>" +
            "    <if test=\"department != null\">" +
            "      and department = #{department}" +
            "   </if>" +
            "    <if test=\"transactor != null\">" +
            " <bind name=\"Key\" value=\"'%'+transactor+'%'\"/>" +
            "        transactor like #{Key} " +
            "    </if>" +
            "    <if test=\"payee != null\">" +
            "      and payee = #{payee}" +
            "   </if>" +
            "    <if test=\"paymoney != null\">" +
            "      and paymoney = #{paymoney}" +
            "   </if>" +
            "    <if test=\"type != null\">" +
            "      and type = #{type}" +
            "   </if>" +
            "    <if test=\"month != null\">" +
            "      and month = #{month}" +
            "   </if>" +
            "    <if test=\"state != null\">" +
            "      and state = #{state}" +
            "   </if>" +
            "    <if test=\"number != null\">" +
            "      and number = #{number}" +
            "   </if>" +
            "</where>" +
            "</script>")
    public int countUser( String department, String transactor,
                              String payee, String paymoney,
                              String type, Date month, Integer state, String number);

    /**
     * 新增支付申请
     * 
     * @param payapply 支付申请
     * @return 结果
     */
    @Insert("insert into payapply (number,department,transactor,payee,paymoney,type,month,state)" +
            "values (#{number},#{department},#{transactor},#{payee},#{paymoney},#{type},#{month},4)")
    public int insertPayapply(Payapply payapply);

    /**
     * 修改支付申请
     * 
     * @param payapply 支付申请
     * @return 结果
     */
    @Update("<script>" +
            "  update payapply" +
            "        <set>" +
            "            <if test=\"null != transactor\"> " +
            "                transactor = #{transactor}," +
            "            </if>" +
            "            <if test=\"null != department\"> " +
            "                department = #{department}," +
            "            </if>" +
            "            <if test=\"null != month\"> " +
            "                month = #{month}," +
            "            </if>" +
            "            <if test=\"null != payee\"> " +
            "                payee = #{payee}," +
            "            </if>" +
            "            <if test=\"null != paymoney\"> " +
            "                paymoney = #{paymoney}," +
            "            </if>" +
            "            <if test=\"null != type\"> " +
            "                type = #{type}," +
            "            </if>" +
            "            <if test=\"null != state\"> " +
            "                state = #{state}," +
            "            </if>" +
            "        </set>" +
            "        where id = #{id}" +
            "</script>")
    public int updatePayapply(Payapply payapply);

    /*修改审批状态*/
    @Update("<script>" +
            "update  payapply " +
            "        <set>" +
            "            <if test=\"null!= state\">" +
            "                state =#{state}," +
            "            </if>" +
            "        </set>" +
            "        where id =#{id}" +
            "</script>")
    public int updateStateById(Payapply payapply);
    /**
     * 删除支付申请
     * 
     * @param id 支付申请主键
     * @return 结果
     */
    public int deletePayapplyById(Integer id);

    /**
     * 批量删除支付申请
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deletePayapplyByIds(Integer[] ids);


}
